package com.cuicuisha.gxyp.manager.service.impl;

import com.cuicuisha.gxyp.manager.mapper.SysRoleMapper;
import com.cuicuisha.gxyp.manager.mapper.SysRoleUserMapper;
import com.cuicuisha.gxyp.manager.service.SysRoleService;
import com.cuicuisha.gxyp.manager.service.SysRoleUserService;
import com.cuicuisha.gxyp.model.dto.system.SysRoleDto;
import com.cuicuisha.gxyp.model.entity.system.SysRole;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName: SysRoleServiceImpl
 * Description:
 *
 * @Author 脆脆鲨
 * @Create 2024-09-11 22:59
 * @Version 1.0
 */
@Service
public class SysRoleServiceImpl implements SysRoleService {

    @Autowired
    private SysRoleMapper sysRoleMapper;

    @Autowired
    private SysRoleUserMapper sysRoleUserMapper;

    @Override
    public PageInfo<SysRole> findByPage(SysRoleDto sysRoleDto, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<SysRole> sysRoleList = sysRoleMapper.findByPage(sysRoleDto);
        PageInfo<SysRole> pageInfo = new PageInfo<>(sysRoleList);
        return pageInfo;
    }

    @Override
    public void saveSysRole(SysRole sysRole) {
        sysRoleMapper.saveSysRole(sysRole);
    }

    @Override
    public void updateSysRole(SysRole sysRole) {
        sysRoleMapper.updateSysRole(sysRole);
    }

    @Override
    public void deleteById(Long roleId) {
        sysRoleMapper.deleteById(roleId);
    }

    @Override
    public Map<String, Object> findAllRoles(Long userId) {
        List<SysRole> sysRoleList = sysRoleMapper.findAllRoles();
        List<Long> sysRoles = sysRoleUserMapper.findSysUserRoleByUserId(userId);
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("allRolesList" , sysRoleList) ;
        resultMap.put("sysUserRoles", sysRoles);
        return resultMap;
    }
}
